package com.fortune.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fortune.dao.MUserDao;
import com.fortune.dto.in.mUser.ChangePasswordDto;
import com.fortune.dto.in.mUser.LoginDto;
import com.fortune.dto.in.mUser.ResetPasswordDto;
import com.fortune.entity.MUserInfo;
import com.fortune.service.MUserService;
import com.fortune.vo.mUser.LoginMUserInfo;
@Service
public class MUserServiceImpl implements MUserService {
	@Autowired
	private MUserDao mUserDao;
	
	@Override
	/**
	 * 0验证通过，1密码输入错误，2手机号不存在
	 */
	public int loginCheck(LoginDto loginDto) {
		String phone = mUserDao.phoneCheck(loginDto);
		if (phone==null || phone.isEmpty()) {
			return 2;
		}else {
			if (phone.equals(loginDto.getPassword())) {
				return 0;
			}
		}
		return 1;
	}

	@Override
	public LoginMUserInfo loginMUserInfo(LoginDto loginDto) {
		LoginMUserInfo loginMUserInfo = mUserDao.loginMUserInfo(loginDto);
		return loginMUserInfo;
	}

	@Override
	public MUserInfo mUserInfo(LoginDto loginDto) {
		MUserInfo mUserInfo = mUserDao.mUserInfo(loginDto);
		return mUserInfo;
	}

	@Override
	public int updatePassword(MUserInfo mUserInfo, ChangePasswordDto changePasswordDto) {
		int result = mUserDao.updatePassword(mUserInfo, changePasswordDto);
		return result;
	}

	@Override
	public int resetPassword(MUserInfo mUserInfo, ResetPasswordDto resetPasswordDto) {
		int result = mUserDao.resetPassword(mUserInfo, resetPasswordDto);
		return result;
	}
}
